package com.genghis.rapidcrm.kernel;

import com.genghis.rapidcrm.kernel.model.BaseLinkModel;
import edu.jetwinner.common.EasyStringUtil;

import java.util.ArrayList;
import java.util.List;

public class RapidLinkModel extends BaseLinkModel<RapidLinkModel> {

    @Override
    protected RapidLinkModel getThis() {
        return this;
    }

    private List<RapidLinkModel> childLinks;

    private String target;

    public RapidLinkModel() {
    }

    public RapidLinkModel(int count) {
        childLinks = new ArrayList<>(count);
    }

    public List<RapidLinkModel> getChildLinks() {
        return childLinks;
    }

    public void setChildLinks(List<RapidLinkModel> childLinks) {
        this.childLinks = childLinks;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    /**
     * Function to get the link url
     *
     * @return <String>
     */
    public String getUrl() {
//        return this.convertToNativeLink();
        return this.linkUrl;
    }

    /**
     * Function to get the link label
     *
     * @return <String>
     */
    public String getLabel() {
        return this.linkLabel;
    }

    /**
     * Function to get the link type
     *
     * @return <String>
     */
    public String getType() {
        return this.linkType;
    }

    /**
     * Function to get the link icon name
     *
     * @return <String>
     */
    public String getIcon() {
        return this.linkIcon;
    }

    /**
     * Function to check whether link has icon or not
     *
     * @return <Boolean> true/false
     */
    public Boolean isIconExists() {
        this.linkIcon = this.getIcon();
        if (EasyStringUtil.isBlank(this.linkIcon)) {
            return false;
        }
        return true;
    }

    /**
     * Function to retrieve the icon path for the link icon
     *
     * @return <String/Boolean> - returns image path if icon exits
     * else returns false;
     */
    public String getIconPath() {
        if (!this.isIconExists()) {
            return "";
        }
//        return Vtiger_Theme::getImagePath(this.getIcon());
        return this.getIcon();
    }

    /**
     * Function to get the link id
     *
     * @return <Number>
     */
    public Integer getId() {
        return this.linkId;
    }

    public RapidLinkModel addChildLink(RapidLinkModel link) {
        this.childLinks.add(link);
        return this;
    }

    public <P> RapidLinkModel add(Consumer1<RapidLinkModel, P> consumer, P value) {
        consumer.accept(this, value);
        return this;
    }

    @FunctionalInterface
    public interface Consumer1<T, P1> {
        void accept(T t, P1 p1);
    }
}
